<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>考勤系统登陆</title>
<link rel="stylesheet" type="text/css"
	href="<%=path%>/jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/jquery-easyui/themes/icon.css">
<style type="text/css">
.div {
	position: absolute;
	width: 500px;
	height: 200px;
	left: 50%;
	top: 50%;
	margin-left: -250px;
	margin-top: -100px;
}
</style>
<script type="text/javascript"
	src="<%=path%>/jquery-easyui/jquery-1.8.0.js"></script>
<script type="text/javascript"
	src="<%=path%>/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.json-2.4.js"></script>
<script type="text/javascript" src="<%=path%>/js/post.js"></script>
<script type="text/javascript">
	var path = '${pageContext.request.contextPath}';

	function setCode() {
		var img = $('#imgCode');
		var src = img.attr("src");
		if (src) {
			src += "?";
		} else {
			src = path + '/imageCode/';
		}
		img.attr("src", src);
	}

	function login() {
		var name = $('#name').val();
		var password = $('#password').val();
		var code = $('#code').val();
		if (name.length == 0) {
			$.messager.alert('提示', '请输入用户名！', 'error');
			return;
		}
		if (password.length == 0) {
			$.messager.alert('提示', '请输入密码！', 'error');
			return;
		}
		if (code.length == 0) {
			$.messager.alert('提示', '请输入验证码！', 'error');
			return;
		}

		sumbit(name, password, code);
	}

	function sumbit(name, password, code) {
		var data = 'name=' + name;
		data += '&password=' + password;
		data += '&code=' + code;
		var url = path + '/user/login';
		$.messager.progress({
			title : '系统提示',
			msg : '登录中，请稍候...'
		});

		$.ajax({
			type : "POST",
			url : url,
			data : data,
			success : function(data) {
				$.messager.progress('close');
				setCode();
				if (data.isSucess) {
					var href = path + '/user/';
					window.location.href = href;
				} else {
					$.messager.alert('错误', data.message, 'error');
				}
			},
			error : function() {
				$.messager.progress('close');
				$.messager.alert('错误', '无法处理！', 'error');
				setCode();
			}
		});
	}
	
	function keydown() {
		var name = $('#name').val();
		var password = $('#password').val();
		var code = $('#code').val();
		
		if (name.length == 0 
			|| password.length == 0 
			|| code.length == 0) {
			return;
		}
		
		login();
	}
	
	$(function () {
		$("input").keydown(function(e){ 
            var curKey = e.which; 
            if(curKey == 13){ 
               	keydown();
                return false; 
            } 
        }); 
        
		if(!($.browser.chrome)){
			$.messager.confirm('询问', '您使用的不是谷歌(chrome)浏览器，是否下载该浏览器?', function(r) {
				if (!r) {
					return;
				}
				var url = 'http://www.google.cn/intl/zh-CN/chrome/browser/?installdataindex=chinabookmarkcontrol&brand=CHUN';
				window.location.href = url;
			});
		}
	});
</script>
</head>
<body>

	<div id="dlg" class="easyui-dialog"
		data-options="iconCls:'icon-save',modal:true,closable:false,draggable:false,title:'员工登陆'"
		style="width:280px;height:170px;">

		<form method="post">
			<table align="center">
				<tr>
					<td>用户名：</td>
					<td><input type="text" id="name" />
					</td>
				</tr>
				<tr>
					<td>密码：</td>
					<td><input type="password" id="password" />
					</td>
				</tr>
				<tr>
					<td>验证码：</td>
					<td><input type="text" id="code" /></td>
				</tr>
				<tr>
					<td><input type="button" value="提交" onclick="login()" />
					</td>
					<td><img id="imgCode" alt="看不清，点击刷新" onclick="setCode();"
						src="<%=path%>/imageCode">
					</td>
				</tr>
			</table>

		</form>
	</div>
</body>
</html>
